<template>
  <div class="News">
    <div class="top">
      <div class="title">行业动态</div>
    </div>
    <div class="main">
      <div class="left">
        <p class="tips" v-if="newsList.length == 0">暂无数据</p>
        <NewsCard v-for="(item, index) in newsList" :key="index" :cardInfo="item" />
      </div>
      <div class="right">
        <RecentNews />
      </div>
    </div>
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-sizes="[10, 15, 20, 25,30,35]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { getNewsList } from "@/api/configApi.js";
import NewsCard from "./components/NewsCard";
import RecentNews from "./components/RecentNews.vue";
export default {
  name: "News",
  components: {
    NewsCard,
    RecentNews
  },
  data() {
    return {
      newsList: [],
      currentPage: 1,
      pageSize: 15,
      total: 0
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      let result = await getNewsList({
        pageSize: this.pageSize,
        page: this.currentPage
      });
      if (result.code == 200) {
        this.newsList = result.data.data;
        this.total = result.data.total;
      }
    },
    handleCurrentChange() {
      this.initial();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.initial();
    }
  }
};
</script>

<style lang="scss" scoped>
.News {
  padding-bottom: 40px;
  .top {
    height: 200px;
    background: $primaryColor;
    text-align: center;
    .title {
      padding-top: 100px;
      margin-bottom: 16px;
      font-family: Open Sans;
      font-weight: 300;
      font-size: 3.375em;
      line-height: 1.26;
      color: rgb(255, 255, 255);
    }
  }
  .pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
  }
  .main {
    // min-height: 1000px;
    width: 80%;
    margin: 50px auto;
    display: flex;
    justify-content: center;
    .left {
      width: 55%;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      align-content: flex-start;
      padding-left: 20px;
      .tips {
        width: 100%;
        height: 300px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    .right {
      width: 25%;
    }
  }

  @media screen and (max-width: 767px) {
    .main {
      width: 100%;
      flex-direction: column;
      align-items: center;
      .left {
        width: 90%;
        padding-left: 0;
      }
      .right {
        width: 90%;
        text-align: center;
      }
    }
  }
}
</style>
